package cn.com.surker.system.controller;

import cn.com.surker.common.AbstractController;
import cn.com.surker.common.Code;
import cn.com.surker.spring.RestResultDto;
import cn.com.surker.thread.ThreadData;
import cn.com.surker.thread.ThreadPools;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 线程管理器
 *
 * @author luotao
 * @date 2025/6/13
 */
@RestController
@RequestMapping("/thread")
public class ThreadController extends AbstractController {

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public RestResultDto allList() {
		List<ThreadData> allThreads = ThreadPools.getAllThreads();
		return RestResultDto.success(allThreads);
	}

	@RequestMapping(value = "/stop", method = RequestMethod.PUT)
	@ResponseBody
	public RestResultDto stop(Long threadId) {
		if (threadId == null) {
			return RestResultDto.fail(Code.PARAM_EMPTY);
		}
		return RestResultDto.success();
	}

}
